<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Smartyclass
 *
 * @author wlf
 */

if(!defined('TinyFW')) exit('Access denied!');

include_once(SYS_PATH . DS . "libs" . DS . "vendor" . DS. "Smarty" . DS . "Smarty.class.php");

class tfSmarty extends Smarty {

    public $view_dir = null;

    public function  __construct() {
        parent::__construct();

        //設置基本的路徑
        if(tfConfig::getConfig('default_layout') == 'default' or tfConfig::getConfig('default_layout' == '')) {
            $this->template_dir =  BASE_PATH . "templates" . DS ;
        } elseif (tfConfig::getConfig('default_layout') == 'application') {
            $this->template_dir =  APP_PATH . tfUri::getAppName() . DS . "templates" . DS ;
        }
        $this->view_dir = $view_dir = APP_PATH . tfUri::getAppName() . DS . "templates" . DS ;
        
        /*if(tfConfig::getConfig('default_layout') == 'default' or tfConfig::getConfig('default_layout' == '')) {
            $this->template_dir =  BASE_PATH . "templates" . DS ;
        }*/
        //$this->template_dir =  APP_PATH . tfUri::getAppName() . DS . "templates" . DS ;
        /*$this->addTemplateDir(APP_PATH . tfUri::getAppName() . DS . "templates" . DS );*/
        
        //echo $this->template_dir;
        $this->compile_dir = BASE_PATH . "template_c" . DS;
        $this->cache_dir = BASE_PATH . "cache" . DS;
        $this->left_delimiter = "<{";
        $this->right_delimiter = "}>";
        if(tfConfig::getConfig('app_environ') == 'dev') {
            $this->force_compile = true;
            $this->force_cache = false;
            //$this->debugging = true;
            
        } elseif(tfConfig::getConfig('app_environ') == 'prod') {
            $this->compile_check = false;
        }
    }

    
    

    public function render_layout($view,$layout = 'default') {

        /*if($this->debugging == true) {
            return $this->display_layout($view, $layout);
        }*/
        //fetch header
        //echo $this->fetch($this->template_dir . DS . "layout" . DS . $layout_filename);
        echo $this->fetch($this->template_dir . DS . "layout" . DS . "header.html");
        //fetch body
        //echo $this->view_dir . $view."<br>";
        if(is_string($view)) {
            echo $this->fetch($this->view_dir . $view);
        } elseif (is_array($view)) {
            foreach($view as $v) {
                echo $this->fetch($this->view_dir . $v);
            }
        }
        
        //fetch footer
        echo $this->fetch($this->template_dir . DS . "layout" . DS . "footer.html");
        
    }
/*    public function display_layout($view, $layout = 'application') {

        $view_dir = APP_PATH . tfUri::getAppName() . DS . "templates" . DS ;
        //fetch header
        echo $this->display($this->template_dir . DS . "layout" . DS . "header.html");

        //fetch body
        if(is_string($view)) {
            echo $this->display($view);

        } elseif (is_array($view)) {
            foreach($view as $v) {
                echo $this->display($v);
            }
        }

        //fetch footer
        echo $this->display($this->template_dir . DS . "layout" . DS . "footer.html");

    }    
*/
    /*
    public function  __destruct() {
        parent::__destruct();
    }
    */    
}
?>
